use serde_derive::{Serialize, Deserialize};
use lucky::{models::{AccountChangeRow as ModelRow}, json::JsonPager,};
use sqlx::{postgres::{PgRow}, row::Row,};
use num_traits::cast::ToPrimitive;
use crate::common::{Pool, models::BackendModel};

#[derive(Serialize, Deserialize, Debug)]
pub struct AccountChange;

impl BackendModel<ModelRow> for AccountChange {

    const TABLE_NAME: &'static str = "account_changes";
    const FIELDS: &'static str = "id, bill_no, user_id, user_name, amount, before_total, after_total, created, in_out, remark";

    fn get_row_filter(r: &PgRow) -> ModelRow {
        unfold_fields!(r, {
            id => i32,
            bill_no => String,
            user_id => i32,
            user_name => String,
            status => i16,
            in_out => i16,
            remark => String,
        }, {amount, before_total, after_total,}, {created,})
    }
}

impl AccountChange {
    record_list!();
}
